package cn.ptu.pmaa.mapper;

import cn.ptu.pmaa.entities.*;
import org.apache.ibatis.annotations.*;

import java.util.List;

public interface AdminMapper {

    //查询所有学生账号信息
    @Select("SELECT * FROM student ")
    public List<Student> getAllStudentInfo();

    //根据id查询学生账号信息
    @Select("SELECT * FROM student WHERE studentid=#{id}")
    public List<Student> getStudentInfoById(@Param("id") String id);

    //根据姓名查询学生账号信息
    @Select("SELECT * FROM student WHERE studentname=#{name}")
    public List<Student> getStudentInfoByName(@Param("name") String name);

    //修改学生账号信息
    @Update("UPDATE student SET studentpwd=#{studentPwd},studentname=#{studentName},studentsex=#{studentSex},studenttel=#{studentTel},studentemail=#{studentEMail}" +
            " WHERE studentid=#{studentId}")
    public int editStudentInfoById(Student student);

    //添加学生账号信息
    @Insert("INSERT INTO student(studentid,studentpwd,roles) VALUES(#{studentId},#{studentPwd},'student')")
    public int addStudent(Student student) throws Exception;

    //批量添加学生账号信息
    @Insert({
            "<script>"+
            "insert into student(studentid,studentpwd,roles) values "+
            "<foreach collection='studentList' item='item' index='index' separator=','>"+
            "(#{item.studentId}, #{item.studentPwd}, #{item.roles})"+
            "</foreach>"+
            "</script>"
    })
    public int addAllStudent(@Param("studentList") List<Student> students);

    //删除学生账号信息
    @Delete("DELETE FROM student WHERE studentid=#{id}")
    public int deleteStudentById(@Param("id") String id);

    //批量删除学生账号信息
    @Delete("<script>" +
            "DELETE FROM student WHERE studentid IN"+
            "<foreach collection='array' item='id' open='(' separator=',' close=')'> " +
            "#{id}" +
            "</foreach>" +
            "</script>")
    public int deleteAllStudentById(String[] id);



    //查询所有教师账号信息
    @Select("SELECT * FROM teacher")
    public List<Teacher> getAllTeacherInfo();

    //根据id查询教师账号信息
    @Select("SELECT * FROM teacher WHERE teacherid=#{id}")
    public List<Teacher> getTeacherInfoById(@Param("id") String id);

    //根据姓名查询教师账号信息
    @Select("SELECT * FROM teacher WHERE teachername=#{name}")
    public List<Teacher> getTeacherInfoByName(@Param("name") String name);

    //修改教师账号信息
    @Update("UPDATE teacher SET teachername=#{teacherName},teacherpwd=#{teacherPwd},teachersex=#{teacherSex},teachertel=#{teacherTel},teacheremail=#{teacherEmail}" +
            " WHERE teacherid=#{teacherId}")
    public int editTeacherInfoById(Teacher teacher);

    //添加教师账号信息
    @Insert("INSERT INTO teacher(teacherid,teacherpwd,roles) VALUES(#{teacherId},#{teacherPwd},'teacher')")
    public int addTeacher(Teacher teacher);

    //删除教师账号信息
    @Delete("DELETE FROM teacher WHERE teacherid=#{id}")
    public int deleteTeacherById(String id);



    //动态查询预约信息：日期，预约人角色，预约人id，开始时间，结束时间，教室，状态
    @Select("<script>"+
            "SELECT * FROM appintment"+
            "<where> "+
            "<if test='app.yyrq != null'>"+
            "yyrq=#{app.yyrq}"+
            "</if>"+
            "<if test='app.yyrjs != null'>"+
            "AND yyrjs=#{app.yyrjs}"+
            "</if>"+
            "<if test='app.yyrid != null'>"+
            "AND yyrid=#{app.yyrid}"+
            "</if>"+
            "<if test='app.yykssj != null'>"+
            "AND yykssj=#{app.yykssj}"+
            "</if>"+
            "<if test='app.yyjssj != null'>"+
            "AND yyjssj=#{app.yyjssj}"+
            "</if>"+
            "<if test='app.yydjsid != null'>"+
            "AND yydjsid=#{app.yydjsid}"+
            "</if>"+
            "<if test='app.state != null'>"+
            "AND state=#{app.state}"+
            "</if>"+
            "<if test='app.yyid != 0'>"+
            "AND yyid=#{app.yyid}"+
            "</if>"+
            "</where>"+
            "</script>")
    public List<Appintment> getAppintment(@Param("app") Appintment appintment);

    //修改预约信息
    @Update("UPDATE appintment SET yydjsid=#{app.yydjsid},yyrq=#{app.yyrq},yykssj=#{app.yykssj},yyjssj=#{app.yyjssj},yyrid=#{app.yyrid},yyrjs=#{app.yyrjs},state=#{app.state}" +
            "WHERE yyid=#{app.yyid}")
    public int editAppintmentById(@Param("app") Appintment appintment);

    //删除预约信息
    @Delete("DELETE FROM appintment WHERE yyid=#{id}")
    public int deleteAppintmentById(@Param("id") String id);

    //批量删除预约信息
    @Delete("<script>" +
            "DELETE FROM appintment WHERE yyid IN"+
            "<foreach collection='array' item='id' open='(' separator=',' close=')'> " +
            "#{id}" +
            "</foreach>" +
            "</script>")
    public int deleteAllAppintmentById(String[] id);

    //查询所有教室信息
    @Select("SELECT * FROM classroom")
    public List<ClassRoom> getAllClassRoomInfo();

    //修改教室信息
    @Update("UPDATE classroom SET jsld=#{jsld},jsfh=#{jsfh},jszws=#{jszws},sfqy=#{sfqy},shzws=#{shzws},shxx=#{shxx},sfkfgxs=#{sfkfgxs} WHERE jsid=#{jsid}")
    public int editClassRoomById(ClassRoom classRoom);

    //添加教室信息
    @Insert("INSERT INTO classroom(jsld,jsfh,jszws,sfqy,shzws,shxx,sfkfgxs,jsid) VALUES(#{jsld},#{jsfh},#{jszws},#{sfqy},#{shzws},#{shxx},#{sfkfgxs},#{jsid})")
    public int addClassRoom(ClassRoom classRoom);

    //删除教室账号信息
    @Delete("DELETE FROM classroom WHERE jsid=#{id}")
    public int deleteClassRoomById(String id);

    //按条件查询教室信息：jsid，jsld，jsfh，jszws，sfqy，sfkfgxs
    @Select("<script>"+
            "SELECT * FROM classroom"+
            "<where> "+
            "<if test='cr.jsid != null'>"+
            "jsid=#{cr.jsid}"+
            "</if>"+
            "<if test='cr.jsld != null'>"+
            "AND jsld=#{cr.jsld}"+
            "</if>"+
            "<if test='cr.jsfh != null'>"+
            "AND jsfh=#{cr.jsfh}"+
            "</if>"+
            "<if test='cr.jszws != null'>"+
            "AND jszws=#{cr.jszws}"+
            "</if>"+
            "<if test='cr.sfqy != null'>"+
            "AND sfqy=#{cr.sfqy}"+
            "</if>"+
            "<if test='cr.sfkfgxs != null'>"+
            "AND sfkfgxs=#{cr.sfkfgxs}"+
            "</if>"+
            "</where>"+
            "</script>")
    public List<ClassRoom> getClassRoomInfo(@Param("cr") ClassRoom classRoom);

    //查看反馈信息
    @Select("SELECT * FROM feedback")
    public List<FeedBack> getFeedBack();

    //删除反馈信息
    @Delete("DELETE FROM feedback WHERE fkid=#{id}")
    public int deleteFeedBack(@Param("id") String id);
}
